﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <title>FaceCat</title>
</head>
<body>
    <canvas id="mycanvas" width="1000" height="700" style="position: fixed; left: 0px; top: 0px;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvas = document.getElementById("mycanvas"); //绘图区域
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        let gPaint = new FCPaint(); //绘图对象
        gPaint.canvas = canvas;
        gPaint.defaultUIStyle = "dark";
        scaleCanvas(gPaint);
        addDefaultEvent(canvas, gPaint);
        //判断是否移动端
        gPaint.isMobile = isMobileMode();
        if (gPaint.isMobile) {
            gPaint.scaleFactorX = 2.5;
            gPaint.scaleFactorY = 2.5;
        }
        /*
        * 创建列
        * grid:表格
        */
        let createGridColumn = function (grid) {
            let gridColumn = new FCGridColumn();
            if (grid.paint.defaultUIStyle == "dark") {
                gridColumn.backColor = "rgb(0,0,0)";
                gridColumn.borderColor = "rgb(50,50,50)";
                gridColumn.textColor = "rgb(255,255,255)";
            } else if (grid.paint.defaultUIStyle == "light") {
                gridColumn.backColor = "rgb(200,200,200)";
                gridColumn.borderColor = "rgb(200,200,200)";
                gridColumn.textColor = "rgb(0,0,0)";
            }
            gridColumn.allowResize = true;
            return gridColumn;
        };

        function callAPI(cmd) {
            if (typeof (facecat) != 'undefined') {
                return facecat.callFaceCat(cmd);
            } else {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", "http://127.0.0.1:9962?" + cmd, false);
                xmlhttp.send(null);
                return xmlhttp.responseText;
            }
            //callAPI("func=fcscript&funcname=getChatData('1234','1234',-1);");
        }

        //创建表格
        let gridLog = new FCGrid();

        /*
        * 初始化表格
        */
        let initGridLog = function () {
            addView(gridLog, gPaint);
            if (gridLog.paint.defaultUIStyle == "dark") {
                gridLog.backColor = "rgb(0,0,0)";
                gridLog.borderColor = "rgb(100,100,100)";
                gridLog.textColor = "rgb(255,255,255)";
                gridLog.scrollBarColor = "rgb(100,100,100)";
            } else if (gridLog.paint.defaultUIStyle == "light") {
                gridLog.backColor = "rgb(255,255,255)";
                gridLog.borderColor = "rgb(150,150,150)";
                gridLog.textColor = "rgb(0,0,0)";
                gridLog.scrollBarColor = "rgb(200,200,200)";
            }
            gridLog.dock = "fill";
            //增加列
            let column = createGridColumn(gridLog);;
            column.text = "消息";
            column.widthStr = "100%";
            gridLog.columns.push(column);
            updateViewDefault(gPaint.views);
        };

        initGridLog();
        /*
         * 重置大小
         */
        let resizeAll = function () {
            canvas.width = document.documentElement.clientWidth;
            canvas.height = document.documentElement.clientHeight;
            scaleCanvas(gPaint);
            updateViewDefault(gPaint.views);
            invalidate(gPaint);
        };

        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();
        };
        //刷新界面
        invalidate(gPaint);

        let room = "1234";
        let pwd = "1234";
        let lastIndex = -1;

        /*
        * 检查绘图
        */
        let checkGridLogPaint = function () {
            let result = callAPI("func=fcscript&funcname=getChatData('" + room + "','" + pwd + "'," + lastIndex + ");");
            if (result.length > 0 && result != "-1,-1") {
                lastIndex = parseInt(result.substr(0, result.indexOf(",")));
                let content = result.substr(result.indexOf(",") + 1)
                let gridRow = new FCGridRow();
                gridLog.rows.push(gridRow);
                let cell = new FCGridCell();
                cell.value = content;
                cell.textColor = "rgb(255,255,255)";
                cell.backColor = "rgb(0,0,0)";
                gridRow.cells.push(cell);
                invalidateView(gridLog);
            }
        };

        //启动秒表
        setInterval(checkGridLogPaint, 100);
    </script>
</body>
</html>
